package com.example.administrator.demob;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class AddActivity extends AppCompatActivity {
    private EditText edtNo;
    private EditText edtName;
    private EditText edtAge;
    private EditText edtSex;
    private Button btnAdd;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add);

        findViews();

        initAdd();
    }

    private void initAdd() {
        btnAdd.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String no = edtNo.getText().toString();
                String name = edtName.getText().toString();
                int age = Integer.parseInt(edtAge.getText().toString());
                String sex = edtSex.getText().toString();

                Student student = new Student(no, name, age, sex);

                Intent intent = new Intent();
                intent.putExtra("STU", student);
                setResult(2001, intent);
                finish();
            }
        });
    }

    private void findViews() {
        edtNo = findViewById(R.id.edt_no);
        edtName = findViewById(R.id.edt_name);
        edtAge = findViewById(R.id.edt_age);
        edtSex = findViewById(R.id.edt_sex);
        btnAdd = findViewById(R.id.btn_add);
    }
}
